package com.gosuncn.service.impl;

import com.gosuncn.FileCopy.InitPoliceCodeMap;
import com.gosuncn.dao.OmsNodeDao;
import com.gosuncn.pojo.OmsNodeInfo;
import com.gosuncn.service.OmsNodeService;
import com.gosuncn.tools.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.PostConstruct;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 监控信息
 * @author zxl
 * @date 2021/8/3
 */
@Service
public class OmsNodeServiceImpl implements OmsNodeService {




    @Autowired
    private OmsNodeDao omsNodeDao;

    private Map<String, String> map = InitPoliceCodeMap.getPoliceCodeMap();

    @PostConstruct
    private void test(){
        System.out.println("PostConstruct 启动成功");
    }



    /**
     * 查询所有的监控记录
     * @return   list列表
     */
    @Override
    public List<OmsNodeInfo> selectList() {
        System.out.println(map);
        return omsNodeDao.selectList();
    }

    /**
     * 通过id查询记录
     * @param id
     * @return
     */
    @Override
    public OmsNodeInfo findOmsNodeById(Integer id) {
        OmsNodeInfo omsNodeInfo = omsNodeDao.findOmsNodeById(id);
        return omsNodeInfo;
    }


    /**
     *添加监控记录
     * @param omsNodeInfo  实体类
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean insert(OmsNodeInfo omsNodeInfo) {
        int i = omsNodeDao.insert(omsNodeInfo);
       //若添加失败i默认为0，若添加成功则返回1
        if (i == 0) {
            return false;
        } else {
            return true;
        }
    }


    /**
     * 更新监控记录
     * @param omsNodeInfo  实体类
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean updateById(OmsNodeInfo omsNodeInfo) {
        int i = omsNodeDao.updateById(omsNodeInfo);
        //若添加失败i默认为0，若添加成功则返回1
        if (i == 0) {
            return false;
        } else {
            return true;
        }

    }



    /**
     * 通过id删除记录
     * @param id
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean deleteById(int id) {
        int i =omsNodeDao.deleteById(id);
        if (i == 0) {
            return false;
        } else {
            return true;
        }
    }
}
